/**
 * Created by PhpStorm.
 * User: 85210755@qq.com
 * NickName: 柏宇娜
 * Date: 2019/11/27 下午2:21
 */

export default class {
  setStorage (key, value) {
    let v = value
    if (typeof v === 'object') {
      v = JSON.stringify(v)
      v = 'obj-' + v
    } else {
      v = 'str-' + v
    }
    window.localStorage.setItem(key, v)
  }
  getStorage (key) {
    let v = window.localStorage.getItem(key)
    if (!v) { return }
    if (v.indexOf('obj-') === 0) {
      v = v.slice(4)
      return JSON.parse(v)
    } else if (v.indexOf('str-') === 0) {
      return v.slice(4)
    }
  }
}
